//
//  ZXFDXuanZeXueShengFileHeaderView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/23.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "ZXFDXuanZeXueShengFileHeaderView.h"

@implementation ZXFDXuanZeXueShengFileHeaderView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        [self initSubView];
        [self layout];
    }
    return self;
}
- (void)initSubView{
    [self addSubview:self.backView];
    [_backView addSubview:self.leftImageView];
    [_backView addSubview:self.fileImageView];
    [_backView addSubview:self.titleLabel];
    [_backView addSubview:self.detailLabel];
    [_backView addSubview:self.selectedButton];
}
- (void)layout{
    [_backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@40);
        make.centerY.equalTo(self.mas_centerY);
        make.right.equalTo(@0).offset(-40);
        make.height.equalTo(@50);
    }];
    [_leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.centerY.equalTo(self->_backView.mas_centerY);
        make.width.equalTo(@19);
        make.height.equalTo(@11);
    }];
    [_fileImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_leftImageView.mas_right).offset(15);
        make.centerY.equalTo(self->_backView.mas_centerY);
        make.width.equalTo(@26);
        make.height.equalTo(@23);
    }];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_fileImageView.mas_right).offset(15);
        make.centerY.equalTo(self->_backView.mas_centerY);
        make.right.equalTo(self->_backView.mas_centerX);
        make.height.equalTo(@11);
    }];
    [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self->_backView.mas_centerX).offset(10);
        make.centerY.equalTo(self->_backView.mas_centerY);
        make.right.equalTo(@0).offset(-50);
        make.height.equalTo(@11);
    }];
    [_selectedButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@0).offset(-10);
        make.centerY.equalTo(self->_backView.mas_centerY);
        make.width.equalTo(@16);
        make.height.equalTo(@16);
    }];
}
- (UIView *)backView{
    if (!_backView) {
        UIView *back = [[UIView alloc]init];
        back.backgroundColor = [UIColor whiteColor];
        _backView = back;
    }
    return _backView;
}
- (UIButton *)selectedButton{
    if (!_selectedButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"yj_xuanze_noxues"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"selecSquir"] forState:UIControlStateSelected];
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        [button setTitleColor:SELECTEDCOLOR forState:0];
        [button addTarget:self action:@selector(selectedButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        _selectedButton = button;
    }
    return _selectedButton;
}
- (void)selectedButtonClick:(UIButton *)sender{
    _selectedButton.selected = !_selectedButton.selected;
    if (_selectedButton.selected == YES) {
        self.selectedAllBlock();
    }else{
        self.noSelectedAllBlock();
    }
}
- (UIImageView *)leftImageView{
    if (!_leftImageView) {
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.image = [UIImage imageNamed:@"arrow_down"];
        _leftImageView = imageView;
    }
    return _leftImageView;
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(422,216.5,145.5,11.5);
        label.numberOfLines = 0;
        label.font = [UIFont systemFontOfSize:14];
        label.text = @"慧阅读2-2-C    Lesson 25";
        label.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
        _titleLabel = label;
    }
    return _titleLabel;
}
- (UIImageView *)fileImageView{
    if (!_fileImageView) {
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.image = [UIImage imageNamed:@"wenJian_file"];
        _fileImageView = imageView;
    }
    return _fileImageView;
}
- (UILabel *)detailLabel{
    if (!_detailLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(422,216.5,145.5,11.5);
        label.numberOfLines = 0;
        label.font = [UIFont systemFontOfSize:12];
        label.text = @"文件：3  大小：82.5MB";
        label.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
        _detailLabel = label;
    }
    return _detailLabel;
}
@end
